import time,requests,json
def getBTCBinance():
    url = 'https://www.binance.com/api/v1/klines?symbol=BTCUSDT&interval=1m'
    headers = {
        "referer": "https://www.binance.com/cn/trade/BTC_USDT",
        "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
    }
    while True:
        try:
            r = requests.get(url, headers=headers,timeout=5)
            datas = reversed(json.loads(r.text)[:-61:-1])
            mlist=[]
            for data in datas:
                mlist2=[]
                data[0]=time.strftime("%H:%M",time.localtime(data[0]//1000))
                mlist2.append(data[0])
                mlist2.append(data[1])
                mlist2.append(data[4])
                mlist2.append(data[3])
                mlist2.append(data[2])
                # mlist2.extend([float(d) for d in data[1:5]])
                # print(mlist2)
                mlist.append(mlist2)
                # mlist.append(data[:5])
            return mlist
        except Exception as e:
            return False

def getBtcBinanceForOne():
    url = 'https://www.binance.com/api/v1/klines?symbol=BTCUSDT&interval=1m'
    headers = {
        "referer": "https://www.binance.com/cn/trade/BTC_USDT",
        "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
    }
    start = time.time()
    while True:
        try:
            r = requests.get(url, headers=headers, timeout=5)
            data = json.loads(r.text)[-1]
            data[0] = time.strftime("%H:%M", time.localtime(data[0] // 1000))
            mlist2=[]
            mlist2.append(data[0])
            mlist2.append(data[1])
            mlist2.append(data[4])
            mlist2.append(data[3])
            mlist2.append(data[2])
            return mlist2
        except Exception as e:
            return False


def getETHBinance():
    url = 'https://www.binance.com/api/v1/klines?symbol=ETHUSDT&interval=1m'
    headers = {
        "referer": "https://www.binance.com/cn/trade/ETH_USDT",
        "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
    }
    while True:
        try:
            r = requests.get(url, headers=headers,timeout=5)
            datas = reversed(json.loads(r.text)[:-61:-1])
            mlist=[]
            for data in datas:
                mlist2=[]
                data[0]=time.strftime("%H:%M",time.localtime(data[0]//1000))
                mlist2.append(data[0])
                mlist2.append(data[1])
                mlist2.append(data[4])
                mlist2.append(data[3])
                mlist2.append(data[2])
                # mlist2.extend([float(d) for d in data[1:5]])
                # print(mlist2)
                mlist.append(mlist2)
                # mlist.append(data[:5])
            return mlist
        except Exception as e:
            return False

def getETHBinanceForOne():
    url = 'https://www.binance.com/api/v1/klines?symbol=ETHUSDT&interval=1m'
    headers = {
        "referer": "https://www.binance.com/cn/trade/ETH_USDT",
        "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
    }
    start = time.time()
    while True:
        try:
            r = requests.get(url, headers=headers, timeout=5)
            data = json.loads(r.text)[-1]
            data[0] = time.strftime("%H:%M", time.localtime(data[0] // 1000))
            mlist2=[]
            mlist2.append(data[0])
            mlist2.append(data[1])
            mlist2.append(data[4])
            mlist2.append(data[3])
            mlist2.append(data[2])
            return mlist2
        except Exception as e:
            return False
